<template>
  <a-modal
    title="好人好事审核"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
    style="top:20px;"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="是否同意发布" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-radio-group buttonStyle="solid" v-decorator="['status',validatorRules.status]">
            <a-radio value="2">是</a-radio>
            <a-radio value="3">否</a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item label="备注说明" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea
            :auto-size="{ minRows: 5, maxRows: 8}"
            placeholder=""
            v-decorator="[ 'memo', {}]"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import {saveGoodThingsVerify} from '@/api/api'
// import pick from 'lodash.pick'

export default {
  name: "GoodThingsVerifyModal",
  data () {
    return {
      visible: false,
      confirmLoading: false,
      confirmDirty: false,
      validatorRules:{
        status:{
          rules: [{
            required: true,
            message: '请选择是否同意发布!'
          }],
        },

      },
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      form:this.$form.createForm(this)
    }
  },
  created () {

  },

  methods: {
    show (record) {
      this.form.resetFields();
      this.visible = true;
      this.model = Object.assign({}, record);
      this.$nextTick(() => {
        this.form.setFieldsValue({
          'status': '2'
        });
      });
    },
    close () {
      this.$emit('close');
      this.visible = false;
      this.disableSubmit = false;
    },
    handleSubmit () {
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          this.confirmLoading = true;
          let formData = Object.assign(this.model, values);
          formData.location = '';
          saveGoodThingsVerify(formData).then((res)=>{
            if(res.success){
              this.$message.success(res.message);
              this.$emit('ok');
            }else{
              this.$message.warning(res.message);
            }
          }).finally(() => {
            this.confirmLoading = false;
            this.close();
          });
        }
      })
    },
    handleCancel () {
      this.close()
    },

  }
}
</script>